package org.jeecg.modules.logistics.dictionaries.hw_dic.service.impl;

import cn.hutool.json.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.jeecg.modules.logistics.dictionaries.hw_dic.entity.HwDicInfo;
import org.jeecg.modules.logistics.dictionaries.hw_dic.mapper.HwDicMapper;
import org.jeecg.modules.logistics.dictionaries.hw_dic.service.IHwDicService;
import org.jeecg.modules.logistics.manage.hw_info.entity.HwInfo;
import org.jeecg.modules.logistics.manage.hw_info.mapper.HwInfoMapper;
import org.jeecg.modules.logistics.manage.hw_info.service.IHwInfoService;
import org.jeecg.modules.logistics.table.hwlx.entity.Hwlx;
import org.jeecg.modules.logistics.table.hwyclx.entity.Hwyclx;
import org.jeecg.modules.logistics.table.hwyslx.entity.Hwyslx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//TODO hwlx        货物类型
//TODO hwyslx      货物运输类型
//TODO hwyclx      货物用车类型
/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2019/12/24  10:55
 */
@Service
@DS("freight")
public class HwDicServiceImpl implements IHwDicService {
    @Autowired
    HwDicMapper hwDicMapper;

    @Override
    public HwDicInfo getHwDicInfo() {
        HwDicInfo hwDicInfo = new HwDicInfo();
        hwDicInfo.setHwlxList(hwDicMapper.getAllHwlx());
        hwDicInfo.setHwyclxList(hwDicMapper.getAllHwyclx());
        hwDicInfo.setHwyslxList(hwDicMapper.getAllHwyslx());
        return null;
    }

    @Override
    public int putHwDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        switch (dic) {
            case "hwlx":
                Hwlx hwlx = (Hwlx) jsonObj.get("data");
                return hwDicMapper.PutHwlx(hwlx);
            case "hwyslx":
                Hwyslx hwyslx = (Hwyslx) jsonObj.get("data");
                return hwDicMapper.PutHwyslx(hwyslx);
            case "hwyclx":
                Hwyclx hwyclx = (Hwyclx) jsonObj.get("data");
                return hwDicMapper.PutHwyclx(hwyclx);
            default:
                return 0;
        }
    }

    @Override
    public int delHwDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        int id = jsonObj.getInt("data");
        switch (dic) {
            case "hwlx":
                return hwDicMapper.DelHwlx(id);
            case "hwyslx":
                return hwDicMapper.DelHwyslx(id);
            case "hwyclx":
                return hwDicMapper.DelHwyclx(id);
            default:
                return 0;
        }
    }

    @Override
    public int addHwDicInfo(String json) {
        JSONObject jsonObj = new JSONObject(json);
        String dic = jsonObj.getStr("dic");
        switch (dic) {
            case "hwlx":
                Hwlx hwlx = (Hwlx) jsonObj.get("data");
                return hwDicMapper.AddHwlx(hwlx);
            case "hwyslx":
                Hwyslx hwyslx = (Hwyslx) jsonObj.get("data");
                return hwDicMapper.AddHwyslx(hwyslx);
            case "hwyclx":
                Hwyclx hwyclx = (Hwyclx) jsonObj.get("data");
                return hwDicMapper.AddHwyclx(hwyclx);
            default:
                return 0;
        }
    }
}
